package cn.changein.framework.kernel.validator.util;

import cn.changein.framework.kernel.model.exception.RequestEmptyException;
import cn.changein.framework.kernel.model.util.ValidateUtil;
import cn.changein.framework.kernel.model.validator.BaseValidatingParam;

/**
 * <p>
 *     校验参数中的参数是否符合规则
 * </p>
 *

 * @Date: 2020-10-27 14:13
 * @Copyright: companyName
 * @Version 1.0
 * @Since JDK1.8
 */
public class CheckUtil {

    public static void validateParameters(Object[] methodParams) {
        for (Object methodParam : methodParams) {
            if (methodParam instanceof BaseValidatingParam) {
                BaseValidatingParam baseValidatingParam = (BaseValidatingParam) methodParam;
                String checkResult = baseValidatingParam.checkParam();

                //如果校验结果不为空，则代表参数校验有空的或者不符合规则的，并且checkResult为参数错误的提示信息
                if (ValidateUtil.isNotEmpty(checkResult)) {
                    throw new RequestEmptyException(checkResult);
                }
            }
        }
    }
}
